home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / 107_01.zip / FIO.1 < prev    next >
Text File  |  1993-06-06  |  5KB  |  145 lines

  1. /*********************************************
  2. *    This source code was contributed by:    *
  3. *                                            *
  4. *         Eric Martz                         *
  5. *         Department of Microbiology         *
  6. *         University of Massachusetts        *
  7. *         Amherst, MA 01003                  *
  8. *                                            *
  9. *    Phones:                                 *
  10. *                                            *
  11. *         Day:      413-545-2325             *
  12. *         Evenings: 413-256-0751             *
  13. *                                            *
  14. *********************************************/
  15.  
  16.  
  17. /* This file is part of a set of three inclusions (fio.1, fio.2, fio.3)
  18. designed to permit the writing of source codes as close as possible to K&R C,
  19. where only "fp = fopen(filename,mode)" is needed to allocate an i/o buffer,
  20. etc. By using this plan, a source code can be portable between a minicomputer
  21. Unix-C system and BSDC. To move the code from the latter to the former, one
  22. need only delete the three "includes". Here is an example of the use of these
  23. inclusions in a "word count" program:
  24.  
  25.     ---------------------------------------------------------
  26.     #include "bdscio.h"
  27.     
  28.     #define NIOBUFS 1
  29.     #include "fio.1"
  30.     
  31.     main(argc,argv)
  32.         int argc;
  33.         char **argv;
  34.         {
  35.     #include "fio.2"
  36.         if (argc == 1) {
  37.             printf("Use: wc filename\n");
  38.             exit(0);
  39.         }
  40.         allcnt(argv[1]);
  41.     }
  42.     allcnt(name)
  43.         char *name;
  44.         {
  45.         unsigned linecnt, charcnt, wordcnt, crcnt, longline;
  46.         int white, linelen, longest;
  47.         int c;
  48.         FILE *fp;
  49.         fp = fopen(name,"r");
  50.         /* [OMITTED HERE IS THE BODY OF THE FUNCTION ] */
  51.         /* IF NEEDED, E. G. FOR WRITING A FILE: */
  52.         fclose(fp);
  53.     }
  54.     #include "fio.3"
  55.     ---------------------------------------------------------*/
  56.  
  57. /* Another example of use may be found in the file backup utility fi.c */
  58.  
  59. /* THIS SEGMENT (fio.1) DECLARES THE I/O BUFFERS NEEDED (_iob), AND A SET OF
  60. FLAGS TO KEEP TRACK OF WHICH ONES ARE IN USE AN ANY GIVEN TIME (bufuse). TAKE
  61. THE EXAMPLE OF A PROGRAM WHICH NEEDS TO HAVE TWO FILES OPEN AT ONCE. MANY MORE
  62. THAN TWO FILES MAY BE OPENED AND CLOSED, BUT WE ARE SUPPOSING THAT NOT MORE
  63. THAN TWO NEED TO BE OPEN SIMULTANEOUSLY. THE "#include fio.1" MUST BE PRECEDED
  64. BY "#define NIOBUFS 2". THIS MEANS _iob[0] THRU _iob[1]. HOWEVER, bufuse[0] IS
  65. USED TO STORE NIOBUFS, THUS THE FIRST BUFFER _iob[0] CORRESPONDS TO THE
  66. BUFFER-USE-FLAG bufuse[1]. */
  67.  
  68. char _iob[NIOBUFS][BUFSIZ];
  69. int bufuse[NIOBUFS+1];
  70.  
  71. /* End of fio.1 */
  72. ongline;
  73.         int white, linelen, longest;
  74.         int c;
  75.         FILE *fp;
  76.         fp = fopen(name,"r");
  77.         /* [OMITTED HERExistent or empty.
  78. backupsubmit├│ ├δ├,%├\├3├Ü┼!q σ*
  79. σ═ñ ╤╤*½&»w#w*└&6#6*
  80. σ═M└&σ═º ╤╤σ*┬&╤s#r*└&6#6═M┬& ═σ┬ ├R *½&σ~#fo#δßs#r═M┬& ═?Çσ*▒&╤s#r═M▒&σ═¬ ╤├▄ *▒ σ!σ═M½&σ*8σ═¡ ╤╤╤╤┴╔Ç???????????ÇÇÇÇ├ö ├C├)├&├δ├\┼!>σ!Aσ═à ╤╤σ*┌&╤s#r═M┌&|╡┬╜ !┴╔*»&»w#w═M┌&σ*ú"σ═ê ╤╤|╡╩-*»&^#Vr+s*ú"σ═ï ╤+σ*/*********************************************
  81. *    This source code was contributed by:    *
  82. *                                            *
  83. *         Eric Martz                         *
  84. *         Department of Microbiology         *
  85. *         University of Massachusetts        *
  86. *         Amherst, MA 01003                  *
  87. *                                            *
  88. *    Phones:                                 *
  89. *                                            *
  90. *         Day:      413-545-2325             *
  91. *         Evenings: 413-256-0751             *
  92. *                                            *
  93. *********************************************/
  94.  
  95.  
  96. /* For an example of the use of "fio.2" and an introduction, see "fio.1". */
  97.  
  98. /* "fio.2" SHOULD BE INCLUDED AS THE FIRST EXECUTABLE CODE IN MAIN;
  99.    IT ZEROS ALL bufuse ELEMENTS, INDICATING THAT NO BUFFERS ARE ASSIGNED
  100.    TO FILES INITIALLY. */
  101.  
  102.     for(bufuse[0]=1;bufuse[0]<=NIOBUFS;bufuse[bufuse[0]++]=0);
  103.  
  104.     /* THE NEXT STATEMENT LEAVES bufuse[0] SET AT NIOBUFS FOR
  105.         USE BY FOPEN, FCLOSE */
  106.  
  107.     bufuse[0] -= 1;
  108.  
  109.     /* End of fio.2 *
  110.                                n a "word count" program:
  111.  
  112.     ---------------------------------------------------------
  113.     #include "bdscio.h"
  114.     
  115.     #define NIOBUFS 1
  116.     #include "fio.1"
  117.     
  118.     main(argc,argv)
  119.         int argc;
  120.         char **argv;
  121.         {
  122.     #include "fio.2"
  123.         if (argc == 1) {
  124.             printf("Use: wc filename\n");
  125.             exit(0);
  126.         }
  127.         allcnt(argv[1]);
  128.     }
  129.     allcnt(name)
  130.         char *name;
  131.         {
  132.         unsigned linecnt, charcn/*********************************************
  133. *    This source code was contributed by:    *
  134. *                                            *
  135. *         Eric Martz                         *
  136. *         Department of Microbiology         *
  137. *         University of Massachusetts        *
  138. *         Amherst, MA 01003                  *
  139. *                                            *
  140. *    Phones:                                 *
  141. *                                            *
  142. *         Day:      413-545-2325             *
  143. *         Evenings: 413-256-0751             *
  144. *                                            *
  145. ****************